//
//  RowDetailTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/4/7.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "RowDetailTableViewCell.h"

@interface RowDetailTableViewCell ()

@property (nonatomic, copy) rowBlock block;

@property(nonatomic,strong)UIImageView *headUrl;

@property(nonatomic,strong)UILabel *userNameLabel;

@property(nonatomic,strong)UIButton *isSelectBtn;

@end

@implementation RowDetailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.isSelectBtn.hidden=NO;

        self.headUrl.image=[UIImage imageNamed:@"contact_head"];

        self.userNameLabel.font=Font_Number(18);

        self.backgroundColor=WhiteColor;

    }
    return self;
}

-(void)isSelectBtnEvent:(UIButton *)sender
{
    sender.selected=!sender.selected;

    if (self.block) {
        self.block(self ,self.model,sender.selected);
    }
}

// isSelectBtn
-(UIButton *)isSelectBtn
{
    if (!_isSelectBtn) {
        _isSelectBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"no_selectIcon"] andWithSelectImage:[UIImage imageNamed:@"selectIcon"] andWithBtnAction:^{

            NSLog(@"sdhjdsfdh33333");

            [self isSelectBtnEvent:self.isSelectBtn];

        }];

        [self.contentView addSubview:_isSelectBtn];
//        _isSelectBtn.backgroundColor=MainColor;
        self.isSelectBtn.tag=999;
        [_isSelectBtn setEnlargeEdgeWithTop:kmargin*3 right:kmargin*3 bottom:kmargin*3 left:kmargin*3];
        [_isSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*6);
            make.centerY.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(kmargin*2,kmargin*2));
        }];
    }
    return _isSelectBtn;
}

-(UIImageView *)headUrl
{
    if (!_headUrl) {
        _headUrl=[UIImageView new];
        [self.contentView addSubview:self.headUrl];
        [_headUrl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3.5,kmargin*3.5));
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(self.isSelectBtn.mas_right).offset(kmargin);
        }];
    }
    return _headUrl;
}


// userNameLabel
- (UILabel *)userNameLabel
{
    if (!_userNameLabel) {
        _userNameLabel=[self getLabelWithText:@"组头名" font:Font_Number(18) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_userNameLabel];
        [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(self.headUrl.mas_right).offset(kmargin);
        }];
    }
    return _userNameLabel;
}


- (void)configModel:(UsersModel *)model andBlock:(rowBlock)block
{
    self.block = block;
    self.model = model;
    self.userNameLabel.text = model.user_name;
}

@end
